package com.handpay.framework.notice;

import android.content.Intent;
import android.os.Bundle;

import com.handpay.zztong.hp.log.HPLog;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;

/**
 * @author yanglun E-mail:sunshine_yangl@sina.com
 * @version 2016-1-20 下午2:39:04
 */
public class ApiNoticeFactory {
    private static ApiNoticeFactory instance;
    private ArrayList<ApiNoticeListener> mApiNoticeListenerArray = new ArrayList<ApiNoticeListener>();

    /**
     *
     * @return
     */
    public static ApiNoticeFactory getInstance() {
        if (instance == null) {
            instance = new ApiNoticeFactory();
        }
        return instance;
    }

    /**
     *
     * @param listener
     */
    public void registerApiNoticeListener(ApiNoticeListener listener) {
        if (mApiNoticeListenerArray != null && !mApiNoticeListenerArray.contains(listener)) {
            mApiNoticeListenerArray.add(listener);
        }
    }

    /**
     *
     * @param listener
     */
    public void unregisterApiNoticeListener(ApiNoticeListener listener) {
        if (mApiNoticeListenerArray != null && mApiNoticeListenerArray.contains(listener)) {
            mApiNoticeListenerArray.remove(listener);
        }
    }

    /**
     *
     * @param action
     * @param bundle
     */
    public void doBroadCastNotice(int action, Bundle bundle) {
        Iterator<ApiNoticeListener> it = mApiNoticeListenerArray.iterator();
        while (it.hasNext()) {
            ApiNoticeListener listener = it.next();
            for (int i = 0; i < listener.getNoticeAction().length; i++) {
                if (listener.getNoticeAction()[i] == action) {
                    listener.onNotifyNotice(action,bundle);
                }
            }
        }
    }
}
